using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using RealState.BusinessObjects;

namespace RealState.DAL
{
	public class ContentTypesDAO
	{
		public ContentTypesDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<ContentTypes> GetContentTypess()
		{
			try
			{
				List<ContentTypes> lstContentTypess = new List<ContentTypes>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTContentTypess",CommandType.StoredProcedure);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					ContentTypes oContentTypes = new ContentTypes();
					oContentTypes.ID = Convert.ToInt32(oDbDataReader["ID"]);
                    oContentTypes.RowNum = Convert.ToInt32(oDbDataReader["Rownum"]);
					oContentTypes.Title = Convert.ToString(oDbDataReader["Title"]);
					oContentTypes.GroupId = Convert.ToInt32(oDbDataReader["GroupId"]);
					lstContentTypess.Add(oContentTypes);
				}
				oDbDataReader.Close();
				return lstContentTypess;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public ContentTypes GetContentTypes(int ID)
		{
			try
			{
				ContentTypes oContentTypes = new ContentTypes();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTContentTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.Int32,ID));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oContentTypes.ID = Convert.ToInt32(oDbDataReader["ID"]);
                 
					oContentTypes.Title = Convert.ToString(oDbDataReader["Title"]);
					oContentTypes.GroupId = Convert.ToInt32(oDbDataReader["GroupId"]);
				}
				oDbDataReader.Close();
				return oContentTypes;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddContentTypes(ContentTypes oContentTypes)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERTContentTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,oContentTypes.Title));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.Int32,oContentTypes.GroupId));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateContentTypes(ContentTypes oContentTypes)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATEContentTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,oContentTypes.Title));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.Int32,oContentTypes.GroupId));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.Int32,oContentTypes.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveContentTypes(ContentTypes oContentTypes)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETEContentTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.Int32,oContentTypes.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveContentTypes(int ID)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETEContentTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.Int32,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
